package cn.itheima.easypoi.pojo;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Main {


    public static void main(String[] args) throws Exception {
        testExcel();
    }



    public static void testExcel() throws Exception{

        //准备员工数据

        Employee e1 = new Employee();

        e1.setId(1L);

        e1.setUsername("张三");

        e1.setEmail("zhang@qq.com");

        Employee e2 = new Employee();

        e2.setId(2L);

        e2.setUsername("李四");

        e2.setEmail("li@qq.com");



        List<Employee> list = new ArrayList<>();

        list.add(e1);

        list.add(e2);



        /**

         * 进行相应的展出

         *  参数1:一些基本配置(表头等)

         *  参数2:导出的类型

         *  参数3:导出的数据

         */

        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(),

                Employee.class, list);



        //保存数据

        FileOutputStream fos = new FileOutputStream("D:/emp.xls");

        workbook.write(fos);

        fos.close();

    }



}


